package br.com.onlinebidding.controller;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import br.com.onlinebidding.dao.ProductDao;
import br.com.onlinebidding.dao.UserDAO;
import br.com.onlinebidding.entity.Product;
import br.com.onlinebidding.entity.User;

@ManagedBean
@SessionScoped
public class ProductController {

	private Product product;
	private DataModel<Product> products; 
	
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	
	public DataModel<Product>getAll(){
		List<Product> lista = new ProductDao().getAll();
		products = new ListDataModel(lista);
		
		return products;
	}
	
	public String prepareToAddProduct (){
		this.product = new Product();
		return "/view/private/product/form-product";
	}
	
	public String prepareToEdictProduct(){
		//product = (Product)products.getRowData();
		this.product = this.products.getRowData();
		return "/view/private/product/edict-product";
	}
	
		
	public String addProduct(){
		ProductDao.insert(this.product);
		product = new Product();
		return "/view/private/product/list-product";
		
	}
	
	public String deleteProduct(){
		Product temp = (Product)products.getRowData();
		ProductDao dao = new ProductDao();
		dao.delete(temp);
		return "/view/private/user/form-user";
	}
	
	public String updatetProduct() {
		ProductDao.update(this.product);
		return "/view/private/product/list-product";
	}
	
	
	
	
}
